import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/*
 * @author zzr
 * @date: 2025/03/15  17:19
 * @description:面向对象思想 List<List<Integer>> 方法老实现一个洗牌 发牌的算法
 */
public class CardList {
    private static final String[] SUIT = {"♦","♥","♠","♣"};

    public static List<Card> buyCard() {
        List<Card> list = new ArrayList<>();
        for (int i = 0; i < SUIT.length; i++) {
            //每种花色 13张
            for (int j = 1; j < 14; j++) {
                String suit = SUIT[i];
                int rank = j;
                Card card = new Card(j, suit);
                list.add(card);
            }
        }
        return list;
    }

    public static void shuffle(List<Card> list) {
        Random random = new Random();
        for (int i = list.size() - 1; i > 0; i--) {
            int random_index = random.nextInt(i);
            swap(list,i,random_index);
        }
    }

    private static void swap(List<Card> list, int i, int random_index) {
        Card tmp = list.get(i);
        list.set(i, list.get(random_index));
        list.set(random_index,tmp);
    }
    public static void main(String[] args) {
        List<Card> list = buyCard();
        System.out.println("牌堆的牌");
        System.out.println(list);

        System.out.println("洗牌");
        shuffle(list);
        System.out.println(list);

        //每个人把字节的牌存起来
        List<List> hand = new ArrayList<>();

        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        //发牌
        for (int i = 0; i < 5; i++) { //i 是发的轮数
            for (int j = 0;j < 3; j++) { //j 是三个人
                Card card = list.remove(0);
                hand.get(j).add(card);
            }
        }

        System.out.println("第一个人的牌：" + hand.get(0));
        System.out.println("第二个人的牌：" + hand.get(1));
        System.out.println("第三个人的牌：" + hand.get(2));
        System.out.println("剩下的牌" + list);
    }
}
